import time
from socket import *
import sys
sk = socket(AF_INET, SOCK_STREAM) 
# sk.bind(("192.168.2.112",10000))
sk.bind((sys.argv[1],10000))
print("start server at",sys.argv[1],":10000")
print("waiting for client...")
sk.listen(10)
csk, caddr = sk.accept()
print("accept client",caddr)
file_data = b""
while True:
    buffer = csk.recv(1024)
    if len(buffer) == 0: break
    file_data += buffer
csk.close()
sk.close()
print("done")
t = time.localtime()
filename = f"_{t.tm_year}_{t.tm_mon}_{t.tm_mday}_{t.tm_hour}_{t.tm_min}_{t.tm_sec}.file"
with open(f"static/{filename}","wb") as f:
    f.write(file_data)
print("Saved file as:",filename)